﻿Public Class LiteralLabel
    'Implements ICtagControl.TenKeyLabel.IfTenkeyLabel

    Private InputColor As Color = Color.Cyan
    Private NormalColor As Color = Drawing.SystemColors.ButtonHighlight

    Private fontLiteral As New Font(Me.Font.Name, Me.Font.Size)
    Private fIsLiteralFontSet As Boolean = False

    Private iRatio As Integer = 60

    Private fIsSameColor As Boolean = False

    Public Event InputCompleted(ByVal Sender As Object)

    Public ReadOnly Property IsEditing As Boolean 'Implements TenKeyLabel.IfTenkeyLabel.IsEditing
        Get
            Return lblValue.IsEditing
        End Get
    End Property

    Public ReadOnly Property IsChanged As Boolean 'Implements TenKeyLabel.IfTenkeyLabel.IsChanged
        Get
            Return lblValue.IsChanged
        End Get
    End Property

    Public Overrides Property BackColor As Color
        Get
            Return lblValue.BackColor
        End Get
        Set(ByVal value As Color)
            If Not lblValue.IsEditing Then
                lblValue.BackColor = value
            End If
        End Set
    End Property

    Public Property SameColor As Boolean
        Get
            SameColor = fIsSameColor
        End Get
        Set(ByVal value As Boolean)
            fIsSameColor = value
            If fIsSameColor Then
                lblLiteral.BackColor = lblValue.BackColor
            Else
                lblLiteral.BackColor = NormalColor
            End If
        End Set
    End Property

    Public Property InputLabel As TenKeyLabel
        Get
            Return lblValue
        End Get
        Set(ByVal value As TenKeyLabel)

        End Set
    End Property

    ''' <summary>
    ''' 提示文字の幅の比率
    ''' </summary>
    ''' <value>0-100の数字</value>
    ''' <remarks></remarks>
    Public Property Ratio As Integer
        Get
            Ratio = iRatio
        End Get
        Set(ByVal value As Integer)
            If value < 0 Then
                iRatio = 0
            ElseIf value > 100 Then
                iRatio = 100
            Else
                iRatio = value
            End If

            LiteralLabel_SizeChanged(Me, New EventArgs)
        End Set
    End Property

    Public Property Literal As String
        Get
            Literal = lblLiteral.Text
        End Get
        Set(ByVal value As String)
            lblLiteral.Text = value
        End Set
    End Property

    Public Property LiteralSize As Integer
        Get
            LiteralSize = lblLiteral.Font.Size
        End Get
        Set(ByVal value As Integer)
            fontLiteral = New Font(Me.Font.Name, value)
            lblLiteral.Font = fontLiteral
            fIsLiteralFontSet = True
        End Set
    End Property

    Public Property LiteralTextAlign As ContentAlignment
        Get
            LiteralTextAlign = lblLiteral.TextAlign
        End Get
        Set(ByVal value As ContentAlignment)
            lblLiteral.TextAlign = value
        End Set
    End Property

    Public Overrides Property Text As String
        Get
            Text = lblValue.Text
        End Get
        Set(ByVal value As String)
            lblValue.Text = value
        End Set
    End Property

    Public Sub ClearText() 'Implements ICtagControl.TenKeyLabel.IfTenkeyLabel.ClearText
        lblValue.ClearText()
    End Sub

    Public Sub EndEdit() ' Implements TenKeyLabel.IfTenkeyLabel.EndEdit
        lblValue.EndEdit()
    End Sub

    Private Sub lblValue_BackColorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblValue.BackColorChanged
        If fIsSameColor AndAlso lblLiteral.BackColor <> lblValue.BackColor Then
            lblLiteral.BackColor = lblValue.BackColor
        End If
    End Sub

    Private Sub lblValue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblValue.Click
        Me.OnClick(e)
    End Sub

    Protected Sub OnEndEdit() Handles lblValue.InputCompleted
        RaiseEvent InputCompleted(Me)
    End Sub

    Private Sub LiteralLabel_FontChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.FontChanged
        If fIsLiteralFontSet Then
            lblLiteral.Font = fontLiteral
        Else
            lblLiteral.Font = Me.Font
        End If
        lblValue.Font = Me.Font
    End Sub

    Private Sub LiteralLabel_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
        lblLiteral.Height = Me.Height
        lblValue.Height = Me.Height

        lblValue.Width = Me.Width * iRatio / 100
        lblLiteral.Width = Me.Width - lblValue.Width

        lblValue.Left = 0
        lblLiteral.Left = lblValue.Right - 1
    End Sub

    Private Sub lblLiteral_TextAlignChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblLiteral.TextAlignChanged
        If lblLiteral.TextAlign = ContentAlignment.BottomCenter OrElse
            lblLiteral.TextAlign = ContentAlignment.BottomLeft OrElse
            lblLiteral.TextAlign = ContentAlignment.BottomRight Then
            lblLiteral.Top = -2
        Else
            lblLiteral.Top = 0
        End If
    End Sub

    Private Sub lblValue_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblValue.MouseLeave
        Me.OnMouseLeave(e)
    End Sub
End Class
